package com.joy.joyusers.utils;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 统一返回结果
 *
 * @param <T> 返回数据类型
 * @author jason
 */
@Getter
@Setter
public class Response<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int status;
    private String message;
    private transient T data;
    private Long total;

    public Response(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public Response(int status, String message, T data, Long total) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    public Response(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public Response<T> success(String message, T data) {
        this.message = message;
        this.status = 200;
        this.data = data;
        return this;
    }


    public Response<T> error(String message, T data) {
        this.message = message;
        this.status = 500;
        this.data = data;
        return this;
    }

    public void setstatus(int status) {
        this.status = status;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }
}